package com.chb.config;

import com.chb.model.MyUserDetails;
import com.chb.model.UserInfo;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;


public class MyUserDetailsConfig implements UserDetailsService {
    /**
     * 加载用户信息
     * @param username the username identifying the user whose data is required.
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if("chb".equals(username)){
            UserInfo userInfo = new UserInfo();
            userInfo.setName("chb");
            userInfo.setPwd(new BCryptPasswordEncoder().encode("987"));
            userInfo.setSex("1");
            userInfo.setPhone("1937393939");
            userInfo.setAuthorities(AuthorityUtils.createAuthorityList("admin","man"));
            return new MyUserDetails(userInfo);
        }
        return null;
    }
}
